package com.zxl.openapi.mq;


import com.zxl.openapi.api.SearchServiceApi;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@RabbitListener(queues = "suibianbigemingzi",autoStartup = "true")
public class LogMQListener {


    @Autowired
    private SearchServiceApi searchServiceApi;


    //方式1 在对应的方法上面添加这个监听
//    @RabbitListener(queues = {"suibianyigemingzi"},autoStartup = "true")
//    public void onMessage(String json) throws Exception {
//        searchServiceApi.add(json);
//    }

    //方式2
    @RabbitHandler//这个写法 必须在类上面添加RabbitListener注解来指定监听哪个队列
    public void onMessage2(String json) throws Exception {
        searchServiceApi.add(json);
    }
}
